package com.yh.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yh.bean.Emp;
import com.yh.bean.t_class;
import com.yh.bean.t_coll;
import com.yh.bean.t_major;
import com.yh.bean.t_stu;
import com.yh.dao.EmpDao;

@Service
public class EmpServiceImpl {
	
	@Autowired
	private EmpDao  empdao;
	
	public Map<String, Object> queryEmp(int currentPage){
		
		PageHelper.startPage(currentPage,6);//取第二页的数据
		List<Emp> list=empdao.listEmp();
		System.out.println("===="+list);
		PageInfo<Emp> p=new PageInfo<Emp>(list);
		Map<String, Object> map=new HashMap<String, Object>();
		map.put("list",list);
		map.put("totalPage", p.getPages());
		System.out.println(list);
		for(Emp emp:list){
			System.out.println(emp.getEmpName());
		}
		System.out.println("总页数是==="+p.getPages());
		System.out.println("进来了么"+currentPage);
		return map;
	}
	
	public boolean updateEmp(){
		Emp emp=new Emp();
		emp.setEmpNo(7839);
		emp.setEmpName("AMY");
		Emp emp2=new Emp();
		emp2.setEmpNo(7903);
		emp2.setEmpName("JIANBO");
		empdao.addEmp(emp2);
		empdao.updateEmp(emp);
		return true;
		
	}
	
	public List<t_coll> searchColl(){
		
		return empdao.searchColl();
	}
    
	//根据学院的编号搜索相对应的专业
	public List<t_major> searchMajor(int collId){
	
		return empdao.searchMajor(collId);
	}
	//根据专业的编号搜索相对应的班级
	
	public List<t_class> searchClass(int majorId){
		
		return empdao.searchClass(majorId);
		
	}
	
   public int addStu(t_stu stu){
		
		return empdao.addStu(stu);
		
	}
	
   //多条件查询学生信息 关联查询
   public Map<String, Object> retrieval(t_stu stu,int currentPage){
       /*System.out.println("手机号码"+stu.getPhone());*/
	   PageHelper.startPage(currentPage,3);//取第二页的数据
	   List<t_stu> stuList=empdao.retrieval(stu);
	   PageInfo<t_stu> p=new PageInfo<t_stu>(stuList);
		Map<String, Object> map=new HashMap<String, Object>();
		
		map.put("list",stuList);
		map.put("totalPage", p.getPages());
	
		/*System.out.println("总页数是==="+p.getPages());
		System.out.println("进来了么"+currentPage);*/
	   return map;
   }
   
   public int deleteStu(String[] stus){
	   int a=empdao.deleteStu(stus);
	   System.out.println(">>>>>>><<<<<<<<"+a);
	return 0;
	   
   }
}
